package com.pzh.assignment.common.bean.vo;

import com.pzh.assignment.common.bean.GlobalConstant;
import com.pzh.assignment.entity.Course;
import lombok.Data;

import java.time.format.DateTimeFormatter;


@Data
public class CourseVO {
    private Integer id;

    private String name;

    private String code;

    private Integer typeId;

    private String createTime;

    private String updateTime;

    public static CourseVO valueOf(Course course) {
        CourseVO vo = new CourseVO();
        vo.setId(course.getId());
        vo.setName(course.getName());
        vo.setCode(course.getCode());
        vo.setTypeId(course.getTypeId());
        if (course.getCreateTime() != null) {
            vo.setCreateTime(course.getCreateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        if (course.getUpdateTime() != null) {
            vo.setUpdateTime(course.getUpdateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        return vo;
    }
}
